package com.example.satu.quizcreator.quiz_creator;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.satu.quizcreator.quiz.Question;
import com.example.satu.quizcreator.R;
import com.example.satu.quizcreator.quiz_creator.interfaces.onAnswerMethodButtonClick;

import roboguice.fragment.RoboFragment;
import roboguice.inject.InjectView;

/**
 * Created by Satu on 2014-09-04.
 */



public class Answer_method_fragment extends RoboFragment {

//    Multi_answer_fragment multi_answer_fragment ;

    @InjectView(R.id.button_basket)
    Button basket_button;

    @InjectView(R.id.button_multi_answer)
    Button multi_answer_button;

    onAnswerMethodButtonClick itemClickListener;

    int ANSWER_METHOD_FLAG;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.answer_method_fragment,null);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        multi_answer_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(itemClickListener != null){
                        setANSWER_METHOD_FLAG(Question.MULTI_ANSWER_METHOD);
                        itemClickListener.multiAnswerButtonClick(Question.MULTI_ANSWER_METHOD);
                }
            }
        });

        basket_button.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             if(itemClickListener != null){
                 setANSWER_METHOD_FLAG(Question.BASKET_ANSWER_METHOD);
                 itemClickListener.multiAnswerButtonClick(Question.BASKET_ANSWER_METHOD);
             }
             }
        });

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if(!(getParentFragment() instanceof onAnswerMethodButtonClick)){
            throw new RuntimeException("Twoja activity nie implementuje onNewsitemClickListneer");
        }
        itemClickListener = (onAnswerMethodButtonClick) getParentFragment();
    }

    public int getANSWER_METHOD_FLAG() {
        return ANSWER_METHOD_FLAG;
    }

    public void setANSWER_METHOD_FLAG(int ANSWER_METHOD_FLAG) {
        this.ANSWER_METHOD_FLAG = ANSWER_METHOD_FLAG;
    }
}
